'use strict';
const BaseController = require('./base');
const { likeRules, dislikeRules } = require('../validator/themeCommentLike');
class ThemeCommentLike extends BaseController {

  // 喜欢的评论
  async like() {
    const { ctx, service, app } = this;
    const errors = app.validator.validate(likeRules, ctx.request.body);
    errors && ctx.helper.commonErr('参数错误', { beans: errors });
    const data = ctx.request.body;
    const user_id = ctx.helper.decodeJwt(ctx);
    const res = await service.themeCommentLike.like({
      ...data,
      user_id,
    });
    ctx.helper.success({ bean: res }, '喜欢成功！');
  }

  // 不喜欢的评论
  async dislike() {
    const { ctx, service, app } = this;
    const errors = app.validator.validate(dislikeRules, ctx.request.body);
    errors && ctx.helper.commonErr('参数错误', { beans: errors });
    const { id } = ctx.request.body;
    const res = await service.themeCommentLike.dislike(id);
    if (!res) ctx.helper.success({}, '取消喜欢失败！');
    ctx.helper.success({ bean: res }, '取消喜欢成功！');
  }
}

module.exports = ThemeCommentLike;
